﻿Public Class frmThemDangKyThue
    Public tableLoaiNha As New DataTable
    Public tableLoaiTin As New DataTable
    Public tableKhuVuc As New DataTable
    Public _taikhoan As String
    '--------------------------------------------------------------------------------------------------------------------
    Public Property Taikhoan() As String
        Get
            Return _taikhoan
        End Get
        Set(ByVal value As String)
            _taikhoan = value
        End Set
    End Property
    '--------------------------------------------------------------------------------------------------------
    Public loainhaDTO As New LoaiNhaDTO
    Public loaiNhaBUS As New LoaiNhaBUS
    '--------------------------------------------------------------------------------------------------------
    Public kvDTO As New KhuVucDTO
    Public kvBUS As New KhuVucBUS
    '--------------------------------------------------------------------------------------------------------------------
    Private Sub frmThemDangKyThue_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        cbSuaChua.Items.Add("1")
        cbSuaChua.Items.Add("2")
        cbSuaChua.Items.Add("3")
        cbSuaChua.Items.Add("4")
        cbSuaChua.Items.Add("5")
        cbSuaChua.Items.Add("6")
        cbSuaChua.Items.Add("7")
        cbSuaChua.Items.Add("8")
        cbSuaChua.Items.Add("9")
        cbSuaChua.Items.Add("10")
        cbSuaChua.SelectedIndex = 2
        '--------------------------------------------------------------------------------------------------------
        tableLoaiNha = loaiNhaBUS.GetAll()
        tableKhuVuc = kvBUS.GetAll()
        '--------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
            cbKhuVuc.Items.Add(tableKhuVuc.Rows(i)("TenKhuVuc"))
        Next
        cbKhuVuc.SelectedIndex = 4
        '--------------------------------------------------------------------------------------------------------
        For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
            cbLoaiNha.Items.Add(tableLoaiNha.Rows(i)("TenLoaiNha"))
        Next
        cbLoaiNha.SelectedIndex = 0
        '--------------------------------------------------------------------------------------------------------

    End Sub
    Private Function KiemTra() As Boolean
        If txtDienTich.Text = "" Or txtGiaThue.Text = "" Or cbSuaChua.Text = "" Or cbLoaiNha.Text = "" Or cbKhuVuc.Text = "" Or cbLoaiNha.Text = "" Then
            Return False
        End If
        Return True
    End Function
    '--------------------------------------------------------------------------------------------------------------------
    Public dkDTO As New DangKyDTO
    Public dkBUS As New DangKyBUS
    '--------------------------------------------------------------------------------------------------------------------
    Public taikhoanDTO As New TaiKhoanDTO
    Public taikhoanBUS As New TaiKhoanBUS
    '--------------------------------------------------------------------------------------------------------------------
    Public svDTO As New SinhVienDTO
    Public svBUS As New SinhVienBUS
    '--------------------------------------------------------------------------------------------------------------------
    Private Sub btnThemMoi_Click(sender As System.Object, e As System.EventArgs) Handles btnThemMoi.Click
        If KiemTra() = True Then
            '--------------------------------------------------------------------------------------------------------------------
            For i As Integer = 0 To tableLoaiNha.Rows.Count - 1
                If tableLoaiNha.Rows(i)("TenLoaiNha").ToString() = cbLoaiNha.Text Then
                    dkDTO.MaLoaiNha = Convert.ToInt32(tableLoaiNha.Rows(i)("MaLoaiNha").ToString())
                    Exit For
                End If
            Next
            '-----------------------------------------------------------------------------------------------------
            For i As Integer = 0 To tableKhuVuc.Rows.Count - 1
                If tableKhuVuc.Rows(i)("TenKhuVuc").ToString() = cbKhuVuc.Text Then
                    dkDTO.MaKhuVucThue = Convert.ToInt32(tableKhuVuc.Rows(i)("MaKhuVuc").ToString())
                    Exit For
                End If
            Next
            '--------------------------------------------------------------------------------------------------------
            If ckXeBuyt.Checked = True Then
                dkDTO.GanTramXeBuyt = 1
            Else
                dkDTO.GanTramXeBuyt = 0
            End If
            If ckOGhep.Checked = True Then
                dkDTO.OGhep = 1
            Else
                dkDTO.OGhep = 0
            End If
            If ckNauAn.Checked = True Then
                dkDTO.ChoNauAn = 1
            Else
                dkDTO.ChoNauAn = 0
            End If
            If ckChungChu.Checked = True Then
                dkDTO.OChungChu = 1
            Else
                dkDTO.OChungChu = 0
            End If
            If ckInternet.Checked = True Then
                dkDTO.Internet = 1
            Else
                dkDTO.Internet = 0
            End If
            If ckTruyenHinhCap.Checked = True Then
                dkDTO.TruyenHinhCap = 1
            Else
                dkDTO.TruyenHinhCap = 0
            End If
            If ckGanCho.Checked = True Then
                dkDTO.GanCho = 1
            Else
                dkDTO.GanCho = 0
            End If
            If ckChoNamThue.Checked = True Then
                dkDTO.ChoNamThue = 1
            Else
                dkDTO.ChoNamThue = 0
            End If
            If ckChoNuThue.Checked = True Then
                dkDTO.ChoNuThue = 1
            Else
                dkDTO.ChoNuThue = 0
            End If
            '--------------------------------------------------------------------------------------------------------------------
            dkDTO.MaDangKy = 1
            dkDTO.DienTich = Convert.ToSingle(txtDienTich.Text)
            dkDTO.GiaThue = Convert.ToInt32(txtGiaThue.Text)
            dkDTO.SucChua = Convert.ToInt32(cbSuaChua.Text) 
            dkDTO.ThoiGianDangKy = DateTime.Now.ToString("dd/MM/yyyy")
            Dim arr() As String = dkDTO.ThoiGianDangKy.Split("/")
            dkDTO.ThoiGianDong = arr(0).ToString() + (Convert.ToInt32(arr(1).ToString) + 1).ToString() + arr(2).ToString()

            dkDTO.TrangThai = 2
            dkDTO.MaSinhVien = svDTO.MaSinhVien
            dkDTO.TieuDe = txtTieuDe.Text
            dkDTO.MaDangKy = 1
            '-------------------------------------------------------------------------------------------------------
            dkBUS.Insert(dkDTO)
            tableDangKyID = dkBUS.GetItemID(svDTO.MaSinhVien)
            frmTrangChu.dgvDangKy.DataSource = tableDangKyID
            frmTrangChu.dgvDangKy.Show()
            Me.Close()
        End If
    End Sub
    Public tableDangKyID As New DataTable
    Private Sub SimpleButton2_Click(sender As System.Object, e As System.EventArgs) Handles SimpleButton2.Click
        Me.Close()
    End Sub

    Private Sub txtDienTich_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtDienTich.KeyPress
        If (Not Char.IsNumber(e.KeyChar) And Not Char.IsControl(e.KeyChar)) Then
            e.Handled = True
        End If
    End Sub

    Private Sub txtGiaThue_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtGiaThue.KeyPress
        If (Not Char.IsNumber(e.KeyChar) And Not Char.IsControl(e.KeyChar)) Then
            e.Handled = True
        End If
    End Sub
End Class